<template>
    <div>
        <h3>管理员登陆</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">账号</td>
                    <td>
                        <input type="text" v-model="queryInfo.userName" />
                    </td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td>
                        <input type="password" v-model="queryInfo.usePwd" />
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" @click="login" class="btn btn-success" value="登录">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import{ref,reactive} from 'vue';
import axios from 'axios';
import {useRouter} from 'vue-router';
const router=useRouter();
//安装 2.导入

//数据
let queryInfo=reactive({
    userName:'',
    usePwd:'',
});
//登陆
const login=()=>{
    //1.非空验证+有效验证
    if(queryInfo.userName==''){
        alert("用户不能为空!")
        return;
    }
    if(queryInfo.usePwd==''){
        alert("密码不能为空!")
        return;
    }
    
    //2.发送网络请求
    axios({
        url:'https://localhost:7001/api/Admin/Login',
        method:'get',
        params:{
            useName:queryInfo.userName,
            usePwd:queryInfo.usePwd,
        }
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert("账号不存在")
            return;
        }
        if(res.data==-2){
            alert("密码错误")
            return;
        }
        router.push('/member')
    })
    .catch(err=>{
        console.log(err);
    });
};

</script>

<style scoped>

</style>